package com.social.socialservice.dal;


import com.social.socialservice.unit.Pager;
import com.social.socialservice.unit.Response;
import com.social.socialservice.unit.SearchRedisHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 热搜相关实现方法
 */
@Service
public class HotSearchDAL {
    @Autowired
    PostDAL postDAL;

    @Autowired
    SearchRedisHelper searchRedisHelper;

    /**
     * 将搜索分页实现好的方法拿过来二次封装、
     * 增加热搜
     */
    public Response getPostSearchDataMapperByQuery(Pager pager){
        //替换#等特殊字符
        pager.setQuery(pager.getQuery().replaceAll("#",""));
        Response res = postDAL.getPostSearchDataMapperByQuery(pager);
        if(res.getState()==200){
            //嵌入Redis热搜功能
            searchRedisHelper.addRedisHotSearch(pager.getQuery());
            return res;
        }else {
            return res;
        }
    }

    /**
     * 读取热搜列表
     * @return
     */
    public Response getHotSearchList() {
        return new Response(200,"获取热搜列表",searchRedisHelper.listHotSearch());
    }
}
